<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>选择颜色</title>
    <style type="text/css">
        #color{font-family: "微软雅黑";
        font-size: 16px;
        color: #ff0000;
        font-weight: bold;
        }
    </style>
</head>
<body>
<div>
    本次选择的颜色是：<span id="color"></span>
    <input type="button" value="选择颜色" onclick="selColor();">
</div>
<script type="text/javascript">
    function selColor(){
        //                0      1     2     3      4     5       6
        var color=Array("红色","黄色","蓝色","绿色","橙色","青色","紫色");
        var num=Math.ceil(Math.random()*7)-1;  // 
        // Math.random() [0-1)   0.99999999999
        // Math.random()*7       0-6.9999999999
        // Math.ceil             0-7
        // -1                    -1-6
        document.getElementById("color").innerHTML=color[num];
    }
</script>
</body>
</html>